import os
import json
import re
url = "t_mg_open.json"
varKey = "openKey"
annotationKey = "openKeyStr"

with open(url,"r",encoding="utf8") as f:
    #jsonStr = f.read()
    jsObjList = json.load(f)

tsTemplate = ""
url = "template.ts"
with open(url,"r",encoding="utf8") as f:
    tsTemplate = f.read()

clsName = "MgOpenEnum"
#print(tsTemplate)

varStr = ""
newLine = "\r"
tabStr = "    "
listLen = len(jsObjList)
for i in range(listLen):
    obj = jsObjList[i]
    annotation = tabStr + "/**{0}*/".format(obj[annotationKey])
    varStr+=annotation+newLine
    varName = tabStr + 'public static {0}:string = "{1}"'.format(obj[varKey],obj[varKey])
    varStr +=varName+newLine


print(type(obj))
clsFileStr = ""
clsFileStr = re.sub(r"\$cls\$",clsName,tsTemplate)
print(clsFileStr)
clsFileStr = re.sub(r"\$vars\$",varStr,clsFileStr)
url = clsName+".ts"
with open(url,'w',encoding="utf8") as f:
    f.write(clsFileStr)